home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- from pyxmpp.utils import from_utf8
- from pyxmpp.iq import Iq
- from pyxmpp.objects import StanzaPayloadObject
- from pyxmpp.utils import to_utf8
- from pyxmpp.xmlextra import common_doc
- from pyxmpp.xmlextra import get_node_ns_uri
- import base64
- import cPickle
- import binascii
- import digsby.accounts as digsby
- import digsbyprofile
- import common
- from digsby.accounts import DIGSBY_ACCOUNTS_NS
- import libxml2
-
- def fix_truncated(short):
- fix_shortname = fix_shortname
- import common.protocolmeta
- return fix_shortname.get(short, short)
-
-
- class Account(StanzaPayloadObject, common.HashedAccount):
- xml_element_name = 'account'
- xml_element_namespace = DIGSBY_ACCOUNTS_NS
-
- def __init__(self, xmlnode_or_acct_or_id = None, protocol = None, username = None, password = None, data = None, action = None):
- if isinstance(xmlnode_or_acct_or_id, libxml2.xmlNode):
- self._Account__from_xml(xmlnode_or_acct_or_id)
- elif isinstance(xmlnode_or_acct_or_id, common.AccountBase):
- acct = xmlnode_or_acct_or_id
- self.id = acct.id
- self.protocol = acct.protocol
- self.username = acct.name
- self.password = acct.password
-
- try:
- self.data = cPickle.dumps(acct.get_options())
- except:
- print 'acct.get_options()', repr(acct.get_options())
- raise
-
- self.action = action
- else:
- self.id = xmlnode_or_acct_or_id
- self.protocol = protocol
- self.username = username
- self.password = password
- self.data = data
- self.action = action
- if not isinstance(self.id, int) or not (self.id >= 0):
- raise ValueError('positive int id is required! (got %r)' % self.id)
-
-
-
- def __repr__(self):
- return '<Digsby.Account %s (%s)>' % (self.protocol, self.username)
-
-
- def __from_xml(self, node):
- if node.type != 'element':
- raise ValueError, 'XML node is not an account element (not en element)'
-
- ns = get_node_ns_uri(node)
- if ns or ns != DIGSBY_ACCOUNTS_NS or node.name != 'account':
- raise ValueError, 'XML node is not an account element'
-
- id = node.prop('id')
- self.id = None if id else None
- username = node.prop('username')
- self.username = None if username else None
- protocol = node.prop('protocol')
- self.protocol = None if protocol else None
- self.protocol = fix_truncated(self.protocol)
- password = node.prop('password')
- self.password = None if password else None
- action = node.prop('action')
- self.action = None if action else None
- self.data = None
- n = node.children
- while n:
- if n.type != 'element':
- n = n.next
- continue
-
- ns = get_node_ns_uri(n)
- if ns and ns != DIGSBY_ACCOUNTS_NS:
- n = n.next
- continue
-
- if n.name == 'data':
- self.data = base64.decodestring(n.getContent())
-
- n = n.next
-
-
- def complete_xml_element(self, xmlnode, _unused):
- if isinstance(self.id, int) and self.id >= 0:
- xmlnode.setProp('id', to_utf8(str(self.id)))
- else:
- raise ValueError, 'self.id must be int'
- None if self.protocol else None
- None if self.username else None
- None if self.password else None
- None if self.action else None
- None if self.data is not None else None
-
-
- def make_push(self, digsby_protocol):
- return digsby.accounts.Accounts([
- self]).make_push(digsby_protocol)
-
-
- def __str__(self):
- n = self.as_xml(doc = common_doc)
- r = n.serialize()
- n.unlinkNode()
- n.freeNode()
- return r
-
-
-